﻿using System;
using System.Collections.Generic;
using System.Text;

using Microsoft.Xna.Framework;

using Daybreak.Core.SceneGraph;
using Daybreak.Core.Terrains;
using Daybreak.Core.Rendering.Pipeline;

namespace Daybreak.Core.Rendering
{
    /// <summary>
    /// Walks through VisibleQueue and builds RenderQueue
    /// </summary>
    public class QueueRenderer : IRender
    {
        private IVisibleQueue _visibleItems;
        private RenderQueue _queue;
        private Pipes.FrameContext _frameData;
        private bool _debugMode = true;

        public QueueRenderer(Pipes.FrameContext frameData, IVisibleQueue items)
        {
            _queue = new RenderQueue();
            _frameData = frameData;
            _visibleItems = items;
        }


        public void RenderScene(Scene scene, Camera camera, float timeSinceLastFrame)
        {

            _queue.ResetQueue(false);

            int itemsCount = _visibleItems.ItemsCount;

            for (int i = 0; i < itemsCount; i++)
            {
                VisibleItem item = _visibleItems.GetItem(i);

                item.RenderSelf(this);
            }


        }


        #region IRender Members

        public bool Debug
        {
            get { return _debugMode; }
            set { _debugMode = value; }
        }

        public RenderQueue RenderQueue
        {
            get { return _queue; }
        }

        public Pipes.FrameContext FrameData
        {
            get { return _frameData; }
        }

        #endregion
    }
}
